#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
启动脚本
用于启动AI测试自动化平台后端服务
"""

import os
import sys
from dotenv import load_dotenv

# 加载环境变量
load_dotenv()

# 添加项目根目录到Python路径
current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, current_dir)

from app import app
from config import current_config

def main():
    """主函数"""
    print("=" * 60)
    print(f"🚀 启动 {current_config.APP_NAME}")
    print(f"📦 版本: {current_config.APP_VERSION}")
    print(f"🌍 环境: {current_config.ENV}")
    debug_text = "开启" if current_config.DEBUG else "关闭"
    print(f"🔧 调试模式: {debug_text}")
    gray_text = "开启" if current_config.GRAY_MODE else "关闭"
    print(f"🎭 灰度模式: {gray_text}")
    print(f"🗄️  数据库: {current_config.MONGODB_DB}")
    print(f"🌐 服务地址: http://{current_config.HOST}:{current_config.PORT}")
    print("=" * 60)
    
    try:
        app.run(
            debug=current_config.DEBUG,
            host=current_config.HOST,
            port=current_config.PORT,
            threaded=True
        )
    except KeyboardInterrupt:
        print("\n👋 服务已停止")
    except Exception as e:
        print(f"❌ 启动失败: {e}")
        sys.exit(1)

if __name__ == '__main__':
    main()